package com.lmoumou.lib_domian

import android.content.Context
import android.content.Intent
import com.lmoumou.lib_domian.entity.Domain
import com.lmoumou.lib_domian.ui.DomainActivity

/**
 * 作者：Lmoumou
 * 时间：2020/8/11 10:21
 */
class DomainLauncher private constructor() {

    companion object {
        @Volatile
        private var instance: DomainLauncher? = null

        fun getInstance(): DomainLauncher {
            return instance ?: synchronized(this) {
                instance ?: DomainLauncher().also { instance = it }
            }
        }
    }

    var launcherActivity: Class<*>? = null
    var settingChangeCallback: SettingChangeCallback? = null
    val domains by lazy { mutableListOf<Domain>() }

    fun startDomainActivity(context: Context, launcherActivity: Class<*>) {
        this.launcherActivity = launcherActivity
        context.startActivity(Intent(context, DomainActivity::class.java))
    }

    fun addDomain(ip: String, name: String): DomainLauncher {
        domains.add(Domain(ip, name))
        return getInstance()
    }

    //////////////////////////////////////////
    interface SettingChangeCallback {
        fun onDomainChange(domain: String)
        fun onDomainResChange(domainRes: String)
    }
}